var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "react", "./component", "components/common/component", "common", "mobile/site", "components/common/base-component", "./shopping-cart-footer"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const React = require("react");
    const component_1 = require("./component");
    const component_2 = require("components/common/component");
    const common_1 = require("common");
    const site_1 = require("mobile/site");
    const base_component_1 = require("components/common/base-component");
    const shopping_cart_footer_1 = require("./shopping-cart-footer");
    let ShoppingCartHeader = class ShoppingCartHeader extends base_component_1.BaseComponent {
        constructor(props) {
            super(props);
            this.state = {};
        }
        edit() {
            // this.shoppingCart.edit();
            // if (this.shoppingCart.status.value == "edit")
            //     this.shoppingCart.status.value = "normal";
            // else
            //     this.shoppingCart.status.value = "edit";
            this.setState({ editSelectedItems: [] });
            let status = this.state.status;
            console.assert(status != null);
            if (status == "edit") {
                this.setState({ status: "normal" });
            }
            else {
                this.setState({ status: "edit" });
            }
        }
        get shoppingCart() {
            if (this._shoppingCart == null) {
                let components = this.masterPage.childComponents[component_1.ShoppingCart.name] || [];
                let c = components[0];
                console.assert(c != null);
                this._shoppingCart = c;
            }
            return this._shoppingCart;
        }
        get shoppingCartFooter() {
            if (this._shoppingCartFooter == null) {
                let components = this.masterPage.childComponents[shopping_cart_footer_1.ShoppingCartFooter.name] || [];
                this._shoppingCartFooter = components[0];
                console.assert(this._shoppingCartFooter != null);
            }
            return this._shoppingCartFooter;
        }
        componentDidMount() {
            setTimeout(() => {
                // 必须要延时,才能获取到控件
                console.assert(this.shoppingCart != null);
                common_1.asyncComponentState(this.shoppingCart, this, "status", "editSelectedItems");
                common_1.asyncComponentState(this.shoppingCartFooter, this, "status");
            }, 100);
        }
        render() {
            let { status } = this.state;
            let showBackButton = true;
            return site_1.defaultNavBar(this.page, {
                title: '购物车',
                right: React.createElement("button", { className: "right-button", style: { width: 'unset' }, onClick: () => __awaiter(this, void 0, void 0, function* () {
                        yield this.edit();
                        this.setState({ status: this.shoppingCart.state.status });
                    }) }, status == 'normal' ? '编辑' : '完成'),
                showBackButton
            });
        }
    };
    ShoppingCartHeader = __decorate([
        component_2.component()
    ], ShoppingCartHeader);
    exports.ShoppingCartHeader = ShoppingCartHeader;
});
